package org.example.maven.mapper;

import org.apache.ibatis.annotations.*;
import org.example.maven.pojo.exhibition.list.AddExhibition;
import org.example.maven.pojo.exhibition.list.ExhibitionListTable;
import org.example.maven.pojo.exhibition.list.ticket.ExhibitionListTicket;
import org.example.maven.pojo.exhibition.list.ticket.ExhibitionTicket;
import org.example.maven.pojo.exhibition.list.ticket.UserPaidTicket;

import java.time.LocalDate;
import java.util.List;

@Mapper
public interface ExhibitionMapper {
    //获取展栏列表
    @Select("SELECT id,name,start_time,end_time,location,cover_image,status,exhi_type from exhibition")
    List<ExhibitionListTable>getAllExhibition();

    //获取展栏数量
    Integer getExhibitionCount();


    //新增展栏
    void addExhibition(AddExhibition addExhibition);

    //设置展栏分类
    void setExhibitionCategory(int exhibitionId, int[] category);

    //根据id查询展栏
    @Select("SELECT id,name,start_time,end_time,location,cover_image,status,exhi_type from exhibition where id=#{id}")
    ExhibitionListTable getExhibitionById(int id);

    //修改展栏票数
    void setExhibitionTicket(int exhibitionId,ExhibitionTicket exhibitionTicket);

    //新增展览票数
    @Insert("INSERT INTO exhibition_ticket (exhibition_id, exhi_date, exhi_number, exhi_price, paid_number) VALUES (#{exhibitionId}, #{exhibitionTicket.date}, #{exhibitionTicket.availableTickets}, #{exhibitionTicket.ticketPrice}, #{exhibitionTicket.paidNumber})")
    @Options(useGeneratedKeys = true, keyProperty = "exhibitionTicket.id", keyColumn = "id")
    void addExhibitionTicket(int exhibitionId,ExhibitionTicket exhibitionTicket);

    //根据exhibitionId和时间查询这个展览是否存在
    @Select("SELECT COUNT(*) FROM exhibition_ticket WHERE exhibition_id = #{exhibitionId} AND exhi_date = #{date}")
    int getExhibitionTicketByExhibitionIdAndDate(@Param("exhibitionId") int exhibitionId, @Param("date") LocalDate date);

    //删除对应id的展览的预约票记录
    void deleteExhibitionTicket(int id);

    //获取对应id的展览的预约票记录
    @Results({
            @Result(property = "date", column = "exhi_date"),
            @Result(property = "availableTickets", column = "exhi_number"),
            @Result(property = "ticketPrice", column = "exhi_price")
    })
    @Select("SELECT exhi_date,exhi_number,exhi_price,paid_number from exhibition_ticket where exhibition_id=#{id}")
    List<ExhibitionTicket> getExhibitionTicket(int id);

    //根据展览id获取订单信息
    @Select("select * from user_paid_ticket where exhibition_id=#{id}")
    List<UserPaidTicket> getExhibitionOrderById(int id);
}
